﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;

namespace Tulde.WindowsPhone.Music
{
    public class AsynchStreamLoaderEventArgs : EventArgs
    {
        public Stream Stream { get; set; }
    }
    public class AsynchStreamLoader
    {
        public event EventHandler<AsynchStreamLoaderEventArgs> StreamReady;
        private WebClient clinet;

        protected virtual void OnStreamReady(Stream s)
        {
            if (this.StreamReady!=null)
            {
                this.StreamReady(this, new AsynchStreamLoaderEventArgs { Stream = s });
            }
        }
        public AsynchStreamLoader()
        {
            this.clinet = new WebClient();
            this.clinet.AllowReadStreamBuffering = true;
            this.clinet.OpenReadCompleted += new OpenReadCompletedEventHandler(clinet_OpenReadCompleted);
        }

        void clinet_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            
        }
        public void GetStream( Uri uri)
        {
            try
            {
                clinet.OpenReadAsync(uri);
            }
            catch (Exception ex)
            {

            }
        }

        void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            this.OnStreamReady(e.Result);
        }
   
    }
}
